package com.yeung.alo;

public class 冒泡排序 {
    public static void main(String[] args) {
        int arr[] = new int[]{1, 2, 3, 4, 5, 6, 7, 0};
        buboleSort(arr);
        for (int i : arr) {
            System.out.println(i);
        }
    }

    public static void buboleSort(int[] tmp) {

        int end = tmp.length - 1;
        while (true) {
            boolean changed = false;
            for (int i = 0; i < end; i++) {
                int pre = tmp[i];
                int suf = tmp[i + 1];
                if (pre > suf) {
                    int tm = pre;
                    tmp[i] = suf;
                    tmp[i + 1] = tm;
                    changed = true;
                }
            }
            if (changed) {
                end--;
            } else {
                break;
            }
        }
    }
}
